package cn.mldn.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * description:
 * Created by gy on 2017/8/20.
 */

public class MyInterceptor implements HandlerInterceptor {

    private Logger log = LoggerFactory.getLogger(this.getClass()) ;

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        this.log.info(" myInterceptor "  + ((HandlerMethod) o).getBean().getClass().getSimpleName());
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        this.log.info(" myInterceptor "  + ((HandlerMethod) o).getBean().getClass().getSimpleName());
        this.log.info(" myInterceptor "  + modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        this.log.info(" myInterceptor 拦截处理完毕 " );
    }
}
